﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using TireService.Data;
using System.Xml.Linq;

namespace TireService.Website
{
    public partial class Daek : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //if (Page.IsPostBack != true)
            //{
            //    if (DateTime.Now.Month >= 9 & DateTime.Now.Month <= 2)
            //    {
            //        // Select winther tires
            //        ddlTireType.Value = "0";
            //    }
            //    else
            //    {
            //        // Select summer tires
            //        ddlTireType.Value = "1";
            //    }

            //    BindTireData(Convert.ToInt32(ddlTireType.Value));
            //}

            
        }

        //private void BindTireData(int TireType)
        //{
        //    XDocument newsXML = XDocument.Load(Server.MapPath("~/App_Data/daek.xml"));

        //    string TireTypeDescription;

        //    ChangeTireType(TireType);

        //    if (TireType == 0)
        //    {
        //        TireTypeDescription = "Vinterdæk";
        //    }
        //    else
        //    {
        //        TireTypeDescription = "Sommerdæk";
        //    }

        //    var tires = from tire in newsXML.Descendants("Daek")
        //                where (tire.Element("Type").Value == TireTypeDescription)
        //                select new
        //                {
        //                    Brand = tire.Element("Maerke").Value,
        //                    Price = tire.Element("Pris").Value,
        //                    Dimension = tire.Element("Dimension").Value
                            
        //                };
            
        //    pgTires.DataSource = tires;
        //    pgTires.Caption = TireTypeDescription;
        //    pgTires.DataBind();
        //}

        ///// <summary>
        ///// Button function that sends email to us with request from user to be contacted with tire prices
        ///// </summary>
        //protected void btnSendRequest_Click(object sender, EventArgs e)
        //{
        //    try
        //    {
        //        string emailaddress = Convert.ToString(ConfigurationManager.AppSettings["EmailAddress"]);
        //        bool test = Convert.ToBoolean(Convert.ToByte(ConfigurationManager.AppSettings["TestEnvironmentOn"]));
        //        string message = String.Format("Kunde har forespurgt på dækpriser<br><br>Navn: {0}<br>Email: {1}<br>Kommentar: {2}<br><br>Dæktype: {3}<br>Dækdimension: {4} / {5} {6}", txtName.Text, txtEmail.Text, txtComment.Text, ddlTireType.Text, ddlWidth.Text, ddlHeight.Text, ddlSize.Text);

        //        Shared email = new Shared();
        //        email.SendEmail(emailaddress, txtEmail.Text, message, "Forespørgsel på dækpriser", true, test, null);
                
        //        // Clear form
        //        txtEmail.Text = "";
        //        txtName.Text = "";
        //        txtComment.Text = "";
        //        ddlWidth.Value = "195,0";
        //        ddlHeight.Value = "65,0";
        //        ddlSize.Value = "15,0";
        //        ddlTireType.Value = "";

        //        // Show message to user
        //        lMessage.Text = "Tak for din forespørgsel - vi vil hurtigst muligt kontakte dig med et tilbud";
        //    }
        //    catch (Exception ex)
        //    {
        //        if ((ex) is ArgumentException)
        //        {
        //            // User error - arguments not valid - show error message
        //            lMessage.Text = ((ArgumentException)ex).Message;
        //        }
        //        else
        //        {
        //            // System error - show general error message
        //            lMessage.Text = "Fejl opstod - venligst prøv igen";
        //        }
        //    }
        //    finally
        //    {
        //        // Update message panel
        //        upMessage.Update();
        //    }
        //}

        //protected void ChangeTireType(int TireType)
        //{
        //    if (TireType == 1)
        //    {
        //        ddlTireType.Value = TireType;
        //        ddlTireType.Text = "Sommerdæk";
        //        btnWinterTires.ImageUrl = "~/Images/Vinterdaek_graa.gif";
        //        btnSummerTires.ImageUrl = "~/Images/Button_sommerdaek.gif";
        //    }
        //    else
        //    {
        //        ddlTireType.Value = TireType;
        //        ddlTireType.Text = "Vinterdæk";
        //        btnWinterTires.ImageUrl = "~/Images/Button_vinterdaek.gif";
        //        btnSummerTires.ImageUrl = "~/Images/Sommerdaek_graa.gif";
        //    }
        //}

        //protected void btnWinterTires_Click(object sender, ImageClickEventArgs e)
        //{
        //    ddlTireType.Value = 0;
        //    ddlTireType.Text = "Vinterdæk";
        //    btnWinterTires.ImageUrl = "~/Images/Button_vinterdaek.gif";
        //    btnSummerTires.ImageUrl = "~/Images/Sommerdaek_graa.gif";
        //    BindTireData(Convert.ToInt32(ddlTireType.Value));
        //}


        //protected void btnSummerTires_Click(object sender, ImageClickEventArgs e)
        //{
        //    ddlTireType.Value = 1;
        //    ddlTireType.Text = "Sommerdæk";
        //    btnWinterTires.ImageUrl = "~/Images/Vinterdaek_graa.gif";
        //    btnSummerTires.ImageUrl = "~/Images/Button_sommerdaek.gif";
        //    BindTireData(Convert.ToInt32(ddlTireType.Value));
        //}

        //protected void ddlTireType_SelectedIndexChanged(object sender, EventArgs e)
        //{
        //    BindTireData(Convert.ToInt32(ddlTireType.Value));
        //}
    }
}